import { ref, onMounted, onUnmounted } from 'vue'
export default function hookBuried(onScrollBottom?: (e: Event) => void) {
  const scrollTop = ref(0)
  const pageScroll = (e: Event) => {
    if (document.documentElement.scrollHeight <= document.documentElement.scrollTop + document.documentElement.clientHeight) {
      onScrollBottom && onScrollBottom(e)
    }
    scrollTop.value = document.documentElement.scrollTop
  }
  onMounted(() => {
    document.addEventListener('scroll', pageScroll)
  })

  onUnmounted(() => {
    document.removeEventListener('scroll', pageScroll)
  })
  return {
    scrollTop
  }
}